﻿using System;
using System.Windows.Threading;
using MadMediaManager.WPFSupport.Interfaces.Services.Threading;

namespace MadMediaManager.WPFSupport.Services.Threading
{
    public class DispatcherOperationWrapper : IDispatcherOperation
    {
        private readonly DispatcherOperation _dispatcherOperation;

        public DispatcherOperationWrapper(DispatcherOperation dispatcherOperation)
        {
            _dispatcherOperation = dispatcherOperation;
        }

        public IDispatcher Dispatcher
        {
            get { return new DispatcherWrapper(_dispatcherOperation.Dispatcher); }
        }

        public DispatcherPriority Priority
        {
            get { return _dispatcherOperation.Priority; }
            set { _dispatcherOperation.Priority = value; }
        }

        public DispatcherOperationStatus Status
        {
            get { return _dispatcherOperation.Status; }
        }

        public object Result
        {
            get { return _dispatcherOperation.Result; }
        }

        public DispatcherOperationStatus Wait()
        {
            return _dispatcherOperation.Wait();
        }

        public DispatcherOperationStatus Wait(TimeSpan timeout)
        {
            return _dispatcherOperation.Wait(timeout);
        }

        public bool Abort()
        {
            return _dispatcherOperation.Abort();
        }

        public event EventHandler Aborted
        {
            add { _dispatcherOperation.Aborted += value; }
            remove { _dispatcherOperation.Aborted -= value; }
        }

        public event EventHandler Completed
        {
            add { _dispatcherOperation.Completed += value; }
            remove { _dispatcherOperation.Completed -= value; }
        }
    }
}
